#!/bin/sh

# must not fail
set -e 

# debug
#set -x 

echo "Starting $0"

nfastgrp=nfast
nfastusr=nfast
nfastuid=504
nfastgid=504
NCIPHER_DISTNAME=ncipher-nCSS-linux-user-2006.zip
NCIPHER_DIRNAME=ncipher-nCSS-linux-user-2006
NCIPHER_UNPACKCMD=unzip


### copy to "install"

if [ ! -f ${DISTFILES_INSTALL}/${NCIPHER_DISTNAME} ] ; then 	
    echo "copying ${NCIPHER_DISTNAME} to ${DISTFILES_INSTALL}"
    cp ${NCIPHER_DISTNAME}     ${DISTFILES_INSTALL}
fi

### unpack if this version dont exist already
if [ -x ${INSTALL_INTO}/${NCIPHER_DIRNAME} ] ;then
    echo "${NCIPHER_DIRNAME} exists, skipping"
else
    cd ${INSTALL_INTO}
    ${NCIPHER_UNPACKCMD} ${DISTFILES_INSTALL}/${NCIPHER_DISTNAME} 
    cd -
fi

cd / 
tar xvf ${INSTALL_INTO}/${NCIPHER_DIRNAME}/ctls/agg.tar
tar xvf ${INSTALL_INTO}/${NCIPHER_DIRNAME}/javasp/agg.tar
tar xvf ${INSTALL_INTO}/${NCIPHER_DIRNAME}/jcecsp/user.tar
tar xvf ${INSTALL_INTO}/${NCIPHER_DIRNAME}/hwsp/agg.tar

grep -q $nfastgrp /etc/group
if [ $? -ne 0 ] ; then
    echo "adding $nfastgrp"
    groupadd -g $nfastgid $nfastgrp
fi

grep -q  $nfastusr /etc/passwd 
if [ $? -ne 0 ] ; then
    echo "creating $nfastusr"
    useradd -m -g $nfastgrp -u $nfastuid $nfastusr
fi



echo "End of $0"

